std.fs.IterableDir.Iterator.next(): Do not assume that FILE_BOTH_DIR_INFORMATION is correctly aligned #17958
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR relaxes the assumed alignment of
FILE_BOTH_DIR_INFORMATION
in the windows implementation ofstd.fs.IterabDir.Iterator.next()
.I am quite new to zig, so I will happily receive any feedback about how this could be done differently - especially concerning the potential performance penalty of this.
Background
The current windows implementation of
std.fs.IterabDir.Iterator.next()
makes the assumption that the FILE_BOTH_DIR_INFORMATION struct returned byNtQueryDirectoryFile
is aligned properly.See https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_both_dir_information
However, in practice this is not always guaranteed due to faulty file system drivers, sandboxing tools, or (in my case) endpoint security software.
Currently, this code will panic on the
@alignCast()
which makes it impossible for the user to work around this issue if it appears.For context, I found that the same issue appeared in Rust:
std::fs::remove_dir_all
occasionally panics on Windows withassertion failed: info.is_aligned()
rust-lang/rust#104530